package com.bxait.toymail.coupon.controller;

import java.util.Arrays;
import java.util.Map;


import com.bxait.com.utils.PageUtils;
import com.bxait.com.utils.R;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bxait.toymail.coupon.entity.CouponEntity;
import com.bxait.toymail.coupon.service.CouponService;

import javax.annotation.Resource;


/**
 * import org.apache.shiro.authz.annotation.RequiresPermissions;
 * 优惠券信息
 * @author chen
 * @email 2277411582@qq.com
 * @date 2023-03-13 22:32:28
 */
@RestController
@RequestMapping("coupon/coupon")
public class CouponController {


    @Resource
    @Qualifier("couponService")
    private CouponService couponService;

    /**
     * @param params
     * @==============History===============<br/>
     * @Description // TODO  获取所以的优惠卷信息
     * @Date 2023/3/16 2023/3/16
     * @Author < a href="2277411582@qq.com">chen</ a>
     * @return [java.util.Map<java.lang.String,java.lang.Object>]
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = couponService.queryPage(params);

        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		CouponEntity coupon = couponService.getById(id);

        return R.ok().put("coupon", coupon);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CouponEntity coupon){
		couponService.save(coupon);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CouponEntity coupon){
		couponService.updateById(coupon);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		couponService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
